package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"quantization_trading/src/models"
	"quantization_trading/src/strategies"
	"quantization_trading/src/util"
)

//创建策略`
func NewStrategy(c *gin.Context)  {
	var data models.Strategy
	c.ShouldBindJSON(&data)
	code := strategies.NewStrategy(data)
	c.JSON(http.StatusOK,gin.H{
		"status":  code,
		"message": util.GetErrMsg(code),
	})
}

//启动策略
func StartStrategy(c *gin.Context)  {
	var s ReqStrategy
	c.ShouldBindJSON(&s)
	code := strategies.StartStrategy(s.StrategyName,s.AccountName)
	c.JSON(http.StatusOK,gin.H{
		"status":  code,
		"message": util.GetErrMsg(code),
	})
}

//停止策略
func StopStrategy(c *gin.Context)  {
	var s ReqStrategy
	c.ShouldBindJSON(&s)
	code := strategies.StopStrategy(s.StrategyName,s.AccountName)
	c.JSON(http.StatusOK,gin.H{
		"status":  code,
		"message": util.GetErrMsg(code),
	})
}

//删除策略
func DelStrategy(c *gin.Context) {
	var s ReqStrategy
	c.ShouldBindJSON(&s)
	code := strategies.DelStrategy(s.StrategyName,s.AccountName)
	c.JSON(http.StatusOK,gin.H{
		"status":  code,
		"message": util.GetErrMsg(code),
	})
}

//查询所有策略
func FindAllStartegy(c *gin.Context)  {
	strategy_list := models.FindAllStrategy()
	c.JSON(http.StatusOK,gin.H{
		"status":  util.SUCCESS,
		"data": strategy_list,
	})
}

//根据用户名查询订单
func FindByAccountNameStrategy(c *gin.Context)  {
	accountName := c.Param("accountName")
	strategy_list := models.FindByAccountNameStrategy(accountName)
	c.JSON(http.StatusOK,gin.H{
		"status":  util.SUCCESS,
		"data": strategy_list,
	})
}